Skip to main content

All Questions

Tagged with
4votes
2answers
405views

Is it possible to apply substring expansion to all elements of a zsh array?

Let's say I'd like to remove the first two and last three characters from all elements of an array e.g. results=( QK9H9UtADCgnG AlaLkCADjQ krsxseW8H1VrU 6nBG94ZbCWQ ) I'd like to end up with results=(...
don_crissti's user avatar
4votes
2answers
1kviews

Zsh use an array in a find command

I would like to rsync over a few files, specified with an array, and delete any other file in a directory. The only approach I can think of is to remove other files using find, and rsync over the ...
simonzack's user avatar
1vote
1answer
2kviews

How to retrieve items from an array of arrays?

Hello StackExchange pros! I am working on a zsh project for macOS. I used typeset to create three associative arrays to hold values, and a fourth array to reference the individual arrays. Is it ...
jamesrg71's user avatar
1vote
0answers
113views

Bash: Parameter Expansion | Parameter Transformation on List of Assoc.Array Keys

Is this possible(bash v5.0.3)? I'd like to dynamically populate a select list using the keys of an associative array (for further code reuse & script automation). Some keys simply require ...
Joshua Hall's user avatar
10votes
5answers
7kviews

Using parameter substitution on a Bash array

I have file.txt that I need to read into a Bash array. Then I need to remove spaces, double quotes and all but the first comma in every entry. Here's how far I've gotten: $ cat file.txt 10,this 2 0 ...
Jon Red's user avatar
0votes
1answer
357views

Shell Function: Sequence of Pipelines as Argument

I have a shell function (in .bashrc) which creates a temp file, executes the arguments (including all sequence of pipelines), redirects it to a temp file and then open it in VS Code. I invoke the ...
Porcupine's user avatar
2votes
4answers
7kviews

How to get bash indexes of parameters array?

I want indexes of parameters, and can get it by dummy var: dummy=( $@ ) echo ${!dummy[@]} but is there straight way to get them, something like $!@ ... not working $!* ... not working ... or ...
Asain Kujovic's user avatar
3votes
2answers
1kviews

Can a bash array be used in place of eval set -- "$params"?

I'm taking a look at the optparse library for bash option parsing, specifically this bit in the generated code: params="" while [ $# -ne 0 ]; do param="$1" shift case "$param" in --my-...
Wildcard's user avatar
13votes
2answers
23kviews

Count number of elements in bash array, where the name of the array is dynamic (i.e. stored in a variable)

Brief statement of the question: Is there built-in bash method to count number of elements in bash array, where the name of the array is dynamic (i.e. stored in a variable), without resorting to ...
drwatsoncode's user avatar
47votes
4answers
32kviews

Bash: slice of positional parameters

How can I get a slice of $@ in Bash without first having to copy all positional parameters to another array like this? argv=( "$@" ) echo "${argv[@]:2}";
n.r.'s user avatar
  • 2,263
75votes
4answers
51kviews

Transform an array into arguments of a command?

I have an array of "options" of a command. my_array=(option1 option2 option3) I want to call this command in a bash script, using the values from array as options. So, command $(some magic here with ...
Somebody still uses you MS-DOS's user avatar

close